﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BoriPeter.FitnessJournal8
{
    public static class ObservableCollectionExtension
    {
        public static ObservableCollection<T> Merge<T>(this ObservableCollection<T> _input1, IEnumerable<T> _input2)
        {
            List<T> itemsToRemove = new List<T>();
            foreach (var item in _input1)
            {
                if (!(_input2.Contains(item)))
                    itemsToRemove.Add(item);
            }
            foreach (var item in itemsToRemove) 
            {
                _input1.Remove(item);
            }

            foreach (var item in _input2)
            {
                if (!(_input1.Contains(item)))
                    _input1.Add(item);
            }

            return _input1;
        }
    }
}
